﻿@using hc.epm.ViewModel;
@model Epm_WorkMainPoints
@{
    ViewBag.Title = "";
}
<style>
    .btn-group {
        margin-top: 0px !important;
        text-align: left !important;
    }

    .selectpicker {
        width: 100%;
        height: 100%;
    }
</style>
<div class="container" style="margin-top:30px;margin-bottom:20px">
    <div class="row">
        <form class="form-horizontal bv-form" id="mainForm">
            <div class="col-lg-12 col-sm-12 mb25">
                <div class="form-group ">
                    <label for="parentName" class="col-sm-2 control-label"><em class="required">*</em>内容分类：</label>
                    <div class="col-sm-8">
                        @Html.DropDownList("DicKey", null, new { @class = "form-control selectpicker  show-tick" })
                        <input type="hidden" name="DicValue" id="DicValue" value="@Model.DicValue" />
                    </div>
                </div>
                <div class="form-group ">
                    <label for="parentName" class="col-sm-2 control-label"><em class="required">*</em>工程内容：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="WorkMain" name="WorkMain" placeholder="请输入工程内容" value="@Model.WorkMain">
                    </div>
                </div>
                <div class="form-group ">
                    <label for="parentName" class="col-sm-2 control-label"><em class="required"></em>默认值：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="WorkMainValues" name="WorkMainValues" placeholder="例：key1,value1;key2,value2" value="@Model.WorkMainValues">
                    </div>
                </div>
                <div class="form-group ">
                    <label for="name" class="col-sm-2 control-label">单位：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="Unit" name="Unit" placeholder="请输入单位" value="@Model.Unit">
                    </div>
                </div>
                <div class="form-group ">
                    <label for="sort" class="col-sm-2 control-label">排序：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="Sort" name="Sort" value="@Model.Sort" placeholder="请输入阶段排序">
                    </div>
                </div>
            </div>
            <div class="col-lg-12 col-sm-12 mb25" style="margin-top:57px">
                <div class="col-lg-6 col-sm-6" style="text-align:right">
                    <input type="button" name="submit" id="save" lay-submit lay-filter="sub" value="提&nbsp;&nbsp;&nbsp;交" class="layui-btn layui-btn-small button-base bg-save" />
                </div>
                <div class="col-lg-6 col-sm-6">
                    <input type="button" value="取&nbsp;&nbsp;&nbsp;消" class="cancel layui-btn layui-btn-small button-base bg-cancel ">
                </div>
                <input type="hidden" name="Id" id="Id" value="@Model.Id" />
            </div>
        </form>
    </div>
</div>
<script>
    $(function () {
        $("#DicKey").change(function () {
            var value = $('#DicKey option:selected').text();
            $("#DicValue").val(value);
        });

        window.onload = function () {
            $('#mainForm').bootstrapValidator({
                excluded: [':hidden'],//[':disabled', ':hidden', ':not(:visible)'] //设置隐藏组件可验证
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    DicKey: {
                        validators: {
                            notEmpty: {
                                message: '内容分类不能为空'
                            }
                        }
                    },
                    WorkMain: {
                        validators: {
                            notEmpty: {
                                message: '工程内容不能为空'
                            }
                        }
                    },
                    Sort: {
                        validators: {
                            stringLength: {
                                max: 10,
                                message: '排序不能超过10字符'
                            }, regexp: {
                                regexp: /^[0-9]+$/i,
                                message: "排序由数字组成"
                            }
                        }
                    }
                }
            });
        }
    });
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //监听提交
        form.on('submit(sub)', function (data) {
            //对表单进行验证
            var bv = $('#mainForm').data('bootstrapValidator');
            bv.validate();
            if (bv.isValid()) {
                var search = $("form").serialize();
                $.post("Edit", search, function (data) {
                    if (data.Flag) {
                        parent.layer.msg("添加成功", { time: 1000, icon: 1 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);//关闭窗口
                            parent.layer.close(alertIndex);
                        });
                    } else {
                        layer.alert(data.Message, { icon: 2 });
                    }
                });
                return true;
            }
        });
        //关闭弹出iframe层
        $('.cancel').on("click", function () {
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);//关闭窗口
        });
    });
</script>